package com.java.distributed.controller;

import com.java.distributed.beans.CommonResult;
import com.java.distributed.beans.MySession;
import com.java.distributed.beans.User;
import com.java.distributed.service.MySessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.concurrent.TimeUnit;


@RestController
public class TestController {

    @Autowired
    private MySessionService mySessionService;

    @GetMapping("/test")
    public CommonResult test(HttpServletRequest request, HttpServletResponse response){
        HttpSession session = request.getSession();
        User currentUser = (User) session.getAttribute("currentUser");
        return new CommonResult(currentUser);
    }

    @GetMapping("/testV2")
    public CommonResult testV2(HttpServletRequest request, HttpServletResponse response){
        MySession session = mySessionService.getSession(request,response);
        User currentUser = (User) session.getAttribute("currentUser");
        return new CommonResult(currentUser);
    }
}
